#include <assert.h>

#include "node.h"

using namespace PBVP;

SuperNode::SuperNode(int i, float _val) 
{
	id = i;
	val = _val;
	LS = 1;
	US = 1;
	dbe = 0;
}

SuperNode::SuperNode(const SuperNode& node)
{
	id = node.id;
	val = node.val;
	LS = node.LS;
	US = node.US;
	dbe = node.dbe;
}

SuperNode& SuperNode::operator = (const SuperNode &node)
{
	if(this == &node)
	{
		return *this;
	}
	id = node.id;
	val = node.val;
	LS = node.LS;
	US = node.US;
	dbe = node.dbe;
	return *this;
}

void SuperNode::addNeighbor(int n, int x) {
	neighbors.push_back(SNodeNeighbor(n, x));
}

int SuperNode::getNeighborAt(int n) {
#ifdef _DEBUG
	assert(n < degree());
#endif
	return neighbors[n].nei;
}

int SuperNode::getTagAt(int n) {
	return neighbors[n].tag;
}

int SuperNode::getNeighborTag(int nid) {
	std::vector<SNodeNeighbor>::iterator it;
	for(it = neighbors.begin(); it != neighbors.end(); ++it) {
		if((*it).nei == nid) return (*it).tag;
	}
	assert(0);
	return -1;

}

void SuperNode::removeNeighbor(int nid)
{
	std::vector<SNodeNeighbor>::iterator it;
	for(it = neighbors.begin(); it != neighbors.end(); ++it) {
		if((*it).nei == nid) {
			neighbors.erase(it);
			return;
		}
	}
	// should never be here
	assert(0);
}

bool SNLess(const SuperNode& sn1, const SuperNode& sn2)
{
	if(sn1.val < sn2.val) return true;
	else if(sn1.val > sn2.val) return false;
	else if(sn1.id < sn2.id) return true;
	return false;
}

